package itheima.zuoye.Test4;

import java.util.Scanner;
//用正则表达式校验用户输入的电话，邮箱，时间是否合法
public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入手机号码：");
        String phone = scanner.next();
        if (!phone.matches("1[3-9]\\d{9}")) {
            System.out.println("手机号码不合法！");

        }else {
            System.out.println("手机号码合法！");
        }
        System.out.println("请输入邮箱:");
        String email = scanner.next();
        if (!email.matches("\\w+@\\w+\\.\\w+")) {
            System.out.println("邮箱格式错误！");

        }else {
            System.out.println("邮箱格式正确！");
        }
        System.out.println("请输入时间：");
        String time = scanner.next();
        if (!time.matches("\\d{4}-\\d{2}-\\d{2}")){
            System.out.println("时间格式错误！");
        }else {
            System.out.println("时间格式正确！");
        }



    }
}
